/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package meteocal.entity;

import java.util.Calendar;
import java.util.Objects;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import meteocal.utility.DateManager;
import meteocal.weather.Weather;

/**
 *
 * @author andrea
 */
@Entity
@DiscriminatorValue(value = "A")
public class AlternativeNotification extends Notification {
    
    @NotNull
    @Enumerated
    private Weather badWeather;
    
    @NotNull
    @Temporal(TemporalType.DATE)
    private Calendar alternative;
    
    /*
    Getters and Setters
    */
    public Weather getBadWeather() {
        return badWeather;
    }
    
    public void setBadWeather(Weather badWeather) {
        this.badWeather = badWeather;
    }
    
    public Calendar getAlternative() {
        return alternative;
    }
    
    public void setAlternative(Calendar alternative) {
        this.alternative = alternative;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final AlternativeNotification other = (AlternativeNotification) obj;
        if (this.badWeather != other.badWeather) {
            return false;
        }
        if (!Objects.equals(this.alternative, other.alternative)) {
            return false;
        }
        
        return super.equals(obj);
    }
    
    @Override
    public int hashCode() {
        return super.hashCode();
    }
    
    @Override
    public String toString(){
        if(alternative != null){
            return String.format("Forecast for your event %s is %s!\nSuggested date: %s",
                    event.getTitle(),
                    badWeather.toString(),
                    DateManager.calendarToString(alternative));
        }
        return String.format("Forecast for your event %s is %s!",
                event.getTitle(),
                badWeather.toString());
    }
    
}
